using UnityEngine;

namespace Exploder.Demo
{
	public class RPGController : MonoBehaviour
	{
		public ExploderObject exploder;

		public ExploderMouseLook MouseLookCamera;

		public Rocket Rocket;

		private float nextShotTimeout;

		private void Start()
		{
			Rocket.HitCallback = OnRocketHit;
		}

		public void OnActivate()
		{
			Rocket.OnActivate();
		}

		private void OnRocketHit(Vector3 position)
		{
			nextShotTimeout = 0.6f;
			exploder.transform.position = position;
			exploder.ExplodeSelf = false;
			exploder.Force = 20f;
			exploder.TargetFragments = 100;
			exploder.Radius = 10f;
			exploder.UseForceVector = false;
			exploder.ExplodeRadius();
			Rocket.Reset();
		}

		private void Update()
		{
			TargetType targetType = TargetManager.Instance.TargetType;
			if (Input.GetMouseButtonDown(0) && nextShotTimeout < 0f && CursorLocking.IsLocked && targetType != TargetType.UseObject)
			{
				MouseLookCamera.Kick();
				Ray ray = MouseLookCamera.mainCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f));
				UnityEngine.Debug.DrawRay(ray.origin, ray.direction * 10f, Color.red, 0f);
				Rocket.Launch(ray);
				nextShotTimeout = float.MaxValue;
			}
			nextShotTimeout -= Time.deltaTime;
		}
	}
}
